package com.jetgege.smartbox.Me;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import com.jetgege.smartbox.Base.BaseActivity;
import com.jetgege.smartbox.R;

import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.OnClick;

public class ForgetPWDActivity extends BaseActivity {

    @BindView(R.id.forgetpwd_toolbar)
    Toolbar forgetpwdToolbar;
    @BindView(R.id.tv_ForgetPWDPhoneTips)
    TextView tvForgetPWDPhoneTips;
    @BindView(R.id.et_ForgetPhoneNum)
    EditText etForgetPhoneNum;
    @BindView(R.id.ib_ForgetPhoneClear)
    ImageButton ibForgetPhoneClear;
    @BindView(R.id.tv_ForgetPWDConfirmNumTips)
    TextView tvForgetPWDConfirmNumTips;
    @BindView(R.id.et_ForgetPWDConfirmNum)
    EditText etForgetPWDConfirmNum;
    @BindView(R.id.ib_ForgetConfirmNumClear)
    ImageButton ibForgetConfirmNumClear;
    @BindView(R.id.bt_ForgetConfirmNum)
    Button btForgetConfirmNum;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_forget_pwd;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initValue();
    }

    private void initValue() {

        forgetpwdToolbar.setTitle("验证手机号码");
        setSupportActionBar(forgetpwdToolbar);
        forgetpwdToolbar.setNavigationIcon(R.drawable.bar_back_btn);
        forgetpwdToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        //调出键盘
        Timer timer = new Timer(true);
        timer.schedule(new TimerTask() {
            public void run() {
                InputMethodManager inputManager = (InputMethodManager) etForgetPhoneNum.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.showSoftInput(etForgetPhoneNum, 0);
            }
        }, 500);
        imputView();
    }

    private void imputView() {
        etForgetPhoneNum.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s.length() > 0) {
                    ibForgetPhoneClear.setVisibility(View.VISIBLE);
                } else ibForgetPhoneClear.setVisibility(View.GONE);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        etForgetPWDConfirmNum.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s.length() > 0) {
                    ibForgetConfirmNumClear.setVisibility(View.VISIBLE);
                } else ibForgetConfirmNumClear.setVisibility(View.GONE);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.forget_pwd, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        finish();
        startActivity(new Intent(ForgetPWDActivity.this,NewPWDActivity.class));
        return true;
    }

    @OnClick({R.id.tv_ForgetPWDPhoneTips, R.id.ib_ForgetPhoneClear, R.id.ib_ForgetConfirmNumClear, R.id.bt_ForgetConfirmNum})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_ForgetPWDPhoneTips:
                break;
            case R.id.ib_ForgetPhoneClear:
                etForgetPhoneNum.setText("");
                break;
            case R.id.ib_ForgetConfirmNumClear:
                etForgetPWDConfirmNum.setText("");
                break;
            case R.id.bt_ForgetConfirmNum:
                break;
        }
    }
}
